errStr = "";
errCount = 0;
submitted = false;

function isSubmitted() {
	if (!submitted) {
		submitted = true;
		return false;
	}
	
	return true;
}

function getLanguageUrl(language) {
	var validLanguage = false;
	
	if (language == "english" || language == "tchinese" || language == "schinese") {
		validLanguage = true;
	}
	
	if (validLanguage) {
		var location = window.location.href;
		var queryIndex = location.indexOf("?");
		
		var newLocation = "";
		var parameters = new Array();
		if (queryIndex >= 0) {
			newLocation = location.substring(0, queryIndex + 1);
			parameters = location.substring(queryIndex + 1, location.length).split("&");
		} else {
			newLocation = newLocation + "?";
		}

		var parameterCount = 0;
		for (var i = 0; i < parameters.length; i ++) {
			var parameter = parameters[i];
			if (parameter.indexOf("lang=") != 0) {
				if (parameterCount > 0) {
					newLocation = newLocation + "&" + parameter;
				} else {
					newLocation = newLocation + parameter;
				}
				parameterCount ++;
			}
		}
		
		if (parameterCount > 0) {
			newLocation = newLocation + "&lang=" + language;
		} else {
			newLocation = newLocation + "lang=" + language;
		}
		
		return newLocation;
	}
	
	return null;
}

function changeLanguage(language) {
	var newUrl = getLanguageUrl(language);
	
	if (newUrl) {
		window.location.href = newUrl;
	}
}

function genErrMsg(asErrStr) {
	errStr += asErrStr + "\n";
	errCount++;
}

function showErr(title) {

	var errMsgObj = document.getElementById("errMsg");	
	var errMsgArray = errStr.split("\n");
	var trObj;
	var tdObj;	
	var textNode;
	var i;


	
	document.getElementById("errTable").style.display="block";
	
	for ( i = errMsgObj.childNodes.length; i > 0 ; i-- ) 
		errMsgObj.removeChild(errMsgObj.childNodes[i-1]);

	if ( errMsgArray.length > 1 ) { 

		textNode = document.createTextNode("");
		errMsgObj.appendChild(textNode);
	}


		
	for (i=0; i < errMsgArray.length - 1; i++) {
		//var err = errMsgArray[i].replace("[","<span class=\"errorCode\">[");
		//var err = err.replace("]","]</span>");
		textNode = document.createTextNode( errMsgArray[i]);
		errMsgObj.appendChild(textNode);
			errMsgObj.appendChild(document.createElement("br"));
	}
	var err = document.getElementById("errMsg").innerHTML;
	
	err=err.replace(/\[/g,"<span class=\"errorCode\">[");
	err=err.replace(/\]/g,"]</span>");
	
	document.getElementById("errMsg").innerHTML=err;
	
}